package top.guinguo.poker;

import javax.swing.*;

/**
 * Created by guin_guo on 2016/9/7.
 */
public class DialogUtil {

    public static void ShowMsg(String msg) {
        JOptionPane.showConfirmDialog(null, msg, "提示", JOptionPane.YES_NO_OPTION);
    }

    public static int InputNumber(String msg) {
        String inputValue ;//= JOptionPane.showInputDialog(msg);
        int inputNumber;
        while (true) {
            try {
                inputValue = JOptionPane.showInputDialog(msg);
                inputNumber = Integer.parseInt(inputValue);
                System.out.println(inputNumber);
                break;
            } catch (NumberFormatException e) {
                DialogUtil.ShowMsg("请输入正确格式的数字");
                //throw new FormatException("请输入正确格式的数字", e);
            }
        }
        return inputNumber;
    }

    public static double InputDouble(String msg) {
        String inputValue ;//= JOptionPane.showInputDialog(msg);
        double inputNumber;
        while (true) {
            try {
                inputValue = JOptionPane.showInputDialog(msg);
                inputNumber = Double.parseDouble(inputValue);
                System.out.println(inputNumber);
                break;
            } catch (NumberFormatException e) {
                DialogUtil.ShowMsg("请输入正确格式的数字");
                //throw new FormatException("请输入正确格式的数字", e);
            }
        }
        return inputNumber;
    }

    public static void PrintText(String text) {
        System.out.println(text);
    }

    public static void main(String[] args) {
        DialogUtil.ShowMsg("test");
        DialogUtil.InputNumber("请输入玩家数量");
        DialogUtil.InputDouble("请输入游戏容忍度");
    }
}
